package com.syh.askservice.controller;


import com.syh.askservice.service.FlaskService;
import com.syh.askservice.service.IAskService;
import com.syh.bscommon.Util.UserHolder;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author syh
 * @since 2024-07-10
 */
@Tag(name = "AskController", description = "问答模块")
@RestController
@RequestMapping("/ask")
@RequiredArgsConstructor
public class AskController {
    private final FlaskService flaskService;
    private final IAskService askService;

    @GetMapping
    @Operation(summary = "获取问答数据")
    public String getData(@RequestParam String question) {
        int id = UserHolder.getUser().getCompanyId();
        int userid = UserHolder.getUser().getId();
        String res = flaskService.ask(question, id, userid);
        if (!res.equals("解析响应体失败") && !res.equals("无查询结果，已执行更新操作。。。")
                && !res.equals("无法识别的问题类型") && !res.equals("请求体序列化失败") && !res.equals("请求失败")) {
            askService.add_ask(question, res, id, userid);
        }
        return res;
    }
    @GetMapping("/getask")
    @Operation(summary = "获取历史问答数据")
    public List<String> getAsk() {
        return askService.getAsk(UserHolder.getUser().getCompanyId(), UserHolder.getUser().getId());

    }
}
